﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

/**
 * pickのテストは別ファイル
 */

namespace MyTestProject {

    public class TestRayIntersection {

        [Fact]
        public void TestConstructor () {
            var ri = new RayIntersection ();
            var vec001 = new float[] { 0, 0, 1 };
            var vec000001 = new float[] { 0, 0, 0, 0, 0, 1 };

            Assert.Equal (0, ri.Distance);
            Assert.Equal (null, ri.Intersected);
            Assert.Equal (vec001, ri.Normal);
            Assert.Equal (vec000001, ri.Ray);
            Assert.Equal (0, ri.SubmeshIndex);
            Assert.Equal (0, ri.Texture[0][0]);
            Assert.Equal (0, ri.Texture[0][1]);
            Assert.Equal (0, ri.Texture[1][0]);
            Assert.Equal (0, ri.Texture[1][1]);
        }

        [Fact]
        public void TestIntersected () {
            var ri = new RayIntersection ();
            var nod = new Group ();
            ri.Intersected = nod;

            Assert.Equal (nod, ri.Intersected);
        }

        [Fact]
        public void TestSetDistance () {
            var ri = new RayIntersection ();
            ri.Distance = 100.0f;

            Assert.Equal (100.0f, ri.Distance);
        }

        [Fact]
        public void TestSetNormal () {
            var ri = new RayIntersection ();
            ri.Normal = new float[] { 1, 2, 3 };

            var expected = new float[] { 1, 2, 3 };

            Assert.Equal (expected, ri.Normal);
        }

        [Fact]
        public void TestSetRay () {
            var ri = new RayIntersection ();
            var ray = new float[] { 1, 2, 3, 4, 5, 6 };
            ri.Ray = ray;

            Assert.Equal (ray, ri.Ray);
        }

        [Fact]
        public void TestSetSubmeshIndex () {
            var ri = new RayIntersection ();
            ri.SubmeshIndex = 100;

            Assert.Equal (100, ri.SubmeshIndex);
        }

        [Fact]
        public void TestSetTexture () {
            var ri = new RayIntersection ();
            var texCoord1 = new float[] { 1, 2 };
            var texCoord2 = new float[] { 3, 4 };
            ri.SetTexture (0, texCoord1);
            ri.SetTexture (1, texCoord2);

            Assert.Equal (texCoord1, ri.Texture[0]);
            Assert.Equal (texCoord2, ri.Texture[1]);
        }

        [Fact]
        public void TestCopyTo () {
            var ri = new RayIntersection ();
            var nod = new Group ();
            var ray = new float[] { 1, 2, 3, 4, 5, 6 };
            var normal = new float[] { 1, 2, 3 };
            var texCoord1 = new float[] { 1, 2 };
            var texCoord2 = new float[] { 3, 4 };
            ri.Intersected = nod;
            ri.Distance = 100.0f;
            ri.Normal = normal;
            ri.Ray = ray;
            ri.SubmeshIndex = 100;
            ri.SetTexture (0, texCoord1);
            ri.SetTexture (1, texCoord2);

            var dup = new RayIntersection ();
            ri.CopyTo (dup);

            Assert.Equal (nod, dup.Intersected);
            Assert.Equal (100.0f, dup.Distance);
            Assert.Equal (normal, dup.Normal);
            Assert.Equal (ray, dup.Ray);
            Assert.Equal (100, dup.SubmeshIndex);
            Assert.Equal (texCoord1, dup.Texture[0]);
            Assert.Equal (texCoord2, dup.Texture[1]);
        }

    }


}
